package com.jthinker.blog.service.impl;

import com.jthinker.blog.dao.BaseDao;
import com.jthinker.blog.service.BaseService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * User: Gang Chen
 * Date: 2015/6/26 22:21
 */
@Service
public abstract class BaseServiceImpl<M extends Serializable, PK extends Serializable> implements BaseService<M, PK>
{

    protected BaseDao<M, PK> baseDao;

    protected abstract void setBaseDao(BaseDao<M, PK> baseDao);

    @Override
    public M get(PK id)
    {
        return baseDao.get(id);
    }

    @Override
    public M save(M model)
    {
        baseDao.save(model);
        return model;
    }

    @Override
    public void saveOrUpdate(M model)
    {
        baseDao.saveOrUpdate(model);
    }

    @Override
    public void update(M model)
    {
        baseDao.update(model);
    }

    @Override
    public void merge(M model)
    {
        baseDao.merge(model);
    }

    @Override
    public void delete(PK id)
    {
        baseDao.delete(id);
    }

    @Override
    public void deleteObject(M model)
    {
        baseDao.deleteObject(model);
    }

    @Override
    public int countAll()
    {
        return baseDao.countAll();
    }

    @Override
    public int count(String hql, Object... paramList)
    {
        return baseDao.count(hql, paramList);
    }

    @Override
    public List<M> listAll()
    {
        return baseDao.listAll();
    }

    @Override
    public boolean isUnique(M entity, String... uniquePropertyNames)
    {
        return baseDao.isUnique(entity, uniquePropertyNames);
    }

    @Override
    public int count(String hql, Map<String, Object> params)
    {
        return baseDao.count(hql, params);
    }

    @Override
    public <T> List<T> list(String hql)
    {
        return baseDao.list(hql);
    }

    @Override
    public <T> List<T> list(String hql, int pn, int pageSize)
    {
        return baseDao.list(hql, pn, pageSize);
    }

    @Override
    public <T> List<T> list(String hql, int pn, int pageSize, String sort, String sortOrder)
    {
        return baseDao.list(hql, pn, pageSize, sort, sortOrder);
    }

    @Override
    public <T> List<T> list(String hql, int pn, int pageSize, Map<String, Object> params)
    {
        return baseDao.list(hql, pn, pageSize, params);
    }

    @Override
    public <T> List<T> list(String hql, int pn, int pageSize, String sort, String sortOrder, Map<String, Object> params)
    {
        return baseDao.list(hql, pn, pageSize, sort, sortOrder, params);
    }
}
